home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 015 / prn2dsk.arc / CAPT30.ASM next >
Encoding:
Assembly Source File  |  1985-03-29  |  5.7 KB  |  206 lines

  1. TITLE  CAPTURE    Version 3.0 - REDIRECT LPT1 TO DISK
  2. PAGE    64,132
  3.  
  4. ; 4/03/84 - requires DOS 2.0 or above
  5. COMMENT |
  6.  
  7.   CAPTURE filespec
  8.  
  9.  Captures all printer output to memory buffer until the buffer
  10.  is full or a '^Z' is received.  The contents of the buffer is
  11.  then written to filespec and a system reset is performed.  I
  12.  use this to copy debug output to disk for later perusal and
  13.  editing. i.e. dis-assemblies of .com files
  14.  
  15.  Please note that the reason for the system reset is that I have
  16.  not found any other way to keep from  hanging the system after
  17.  the file is written.  If anyone knows how please let me hear
  18.  about it.  CAPTURE does not support path names.
  19.  
  20. Note that to generate a ^Z type the F6 key or control Z while in
  21. DOS.  CAPTURE actually watches for the string '^Z' to terminate, not
  22. 1AH as would normally be expected.  The size of the memory buffer
  23. can be changed by changing the BUFSIZ equate to whatever you wish
  24. and then reassembling, linking and converting to a '.COM' file with
  25. EXE2BIN.
  26.  
  27.   Ted Reuss c/o South Texas Software, Inc.
  28.         5847 San Felipe, Suite 1800
  29.         Houston, TX  77057
  30.         (713) 783-9321
  31.     |
  32.  
  33. BUFSIZ    EQU    8000H            ; buffer size (32768)
  34. CR    EQU    0DH            ; carriage return
  35. LF    EQU    0AH            ; linefeed
  36. EOF    EQU    1AH            ; DOS end of file
  37. UFCB1    EQU    DS:005CH        ; DOS file control blk
  38.  
  39. @STROUT EQU    9H            ; print string
  40. @CLOSF    EQU    10H            ; close file
  41. @CRTEF    EQU    16H            ; create file
  42. @SETDTA EQU    1AH            ; set disk transfer addr
  43. @WRRND    EQU    22H            ; random write
  44. @SETRND EQU    24H            ; set random record field
  45. @SETINT EQU    25H            ; set interrupt vector
  46. @WRBLK    EQU    28H            ; random block write
  47. @GETCIF EQU    34H            ; get CIF pointer
  48. @GETINT EQU    35H            ; get interrupt vector
  49.  
  50. ; A MACRO to call DOS via interrupt 21H.  Function codes are
  51. ; passed in AH.  DL/DX are set, if passed, according to the
  52. ; function number/type.
  53.  
  54. DOSCALL MACRO    FUNC,PARM1
  55. f_c    =    FUNC
  56. IFNB <PARM1>
  57. if f_c eq 2 or (f_c ge 4 and f_c le 6) or f_c eq 0EH or f_c eq 2EH
  58.     MOV    DL,PARM1
  59. ELSE
  60.     MOV    DX,OFFSET PARM1
  61. ENDIF
  62. ENDIF
  63.     MOV    AH,FUNC
  64.     INT    21H
  65.     ENDM
  66.  
  67. ; A MACRO to set an interrupt vector.
  68. ;  SETINT interrupt_number, segment_addr, offset_addr
  69.  
  70. SETINT    MACRO    inbr,iseg,iofs
  71.     MOV    AX,iseg
  72.     MOV    DS,AX
  73.     MOV    DX,iofs
  74.     MOV    AX,2500H+inbr
  75.     INT    21H
  76.     ENDM
  77.  
  78. ; Note that an INT 19H should be enough to reboot, but on my system which
  79. ; uses a Tallgrass 12 meg disk I have to reset the following interrupt
  80. ; vectors to prevent the system from hanging.  When I first figured this
  81. ; out I did not take the time to elimate each one and therefore I may be
  82. ; resetting more than neccessary.
  83.  
  84. REBOOT    MACRO
  85.     SETINT    09H,0F000H,0E987H    ; Keyboard
  86.     SETINT    0BH,0,0         ; Comm 2, set by TGTBIO
  87.     SETINT    10H,0F000H,0F065H    ; Video
  88.     SETINT    16H,0F000H,0E82EH    ; Keyboard I/O
  89.     SETINT    1CH,0F000H,0FF53H    ; Timer Tick
  90.     INT    19H            ; BIOS bootstrap
  91.     ENDM
  92.  
  93.  
  94. CAPTURE SEGMENT PUBLIC 'CODE'
  95.     ASSUME    CS:CAPTURE,DS:CAPTURE,ES:NOTHING
  96. SEGADDR =    $
  97.     ORG    100H            ;use EXE2BIN -> .com file
  98. START:    JMP    INIT            ; go do initialization
  99.  
  100. XFLAG    DB    0            ; set when done
  101. BUFSEG    DW    0            ; segment addr of buffer
  102. BUFLEN    DW    BUFSIZ            ; buffer length
  103. BUFPTR    DW    -1            ; buffer input pointer
  104. ;
  105. ;    PRINTER INTERRUPT ROUTINE - INT 17
  106. ;
  107. INT_17    LABEL    NEAR
  108.     STI                ;interrupts back on
  109.     OR    AH,AH
  110.     JZ    L0005            ; If print char call
  111. L0001:    DB    0EAH            ; Prefix byte for FAR jump
  112. O17_IP    DW    0            ; IP of original int 17H
  113. O17_CS    DW    0            ; CS of original int 17H
  114. L0005:    CMP    CS:XFLAG,1
  115.     JZ    L0001            ; If done
  116.     PUSH    AX            ;save all registers
  117.     PUSH    BX
  118.     PUSH    CX
  119.     PUSH    DX
  120.     PUSH    DS
  121.     PUSH    ES
  122.     PUSH    CS            ; establish our data
  123.     POP    DS            ;  segment address
  124. L0010:
  125.     MOV    ES,BUFSEG        ; ES <- buffer segment
  126.     INC    BUFPTR            ; increment buffer pointer
  127.     MOV    BX,BUFPTR        ; BX <- buffer pointer
  128.     CMP    BX,BUFLEN        ; buffer full?
  129.     JA    L0020            ;  yes .. go write it
  130.     MOV    ES:[BX],AL        ; put character in buffer
  131.     CMP    AL,'Z'                  ; check for ^Z
  132.     JNZ    L0030            ;  nope
  133.     CMP    BYTE PTR ES:[BX-1],'^'  ;  for sure?
  134.     JNZ    L0030            ;  nope .. return
  135. L0020:
  136.     MOV    XFLAG,1         ; set done flag
  137.     PUSH    DS            ; save DS
  138.     PUSH    ES            ; make
  139.     POP    DS            ; DS = ES
  140.     XOR    DX,DX            ; DX = 0
  141.     DOSCALL @SETDTA         ; set DTA to DS:0
  142.     POP    DS            ; restore DS
  143.     DOSCALL @WRRND,UFCB1        ; write buffer
  144.     DOSCALL @CLOSF,UFCB1        ; close file
  145.     REBOOT                ; Re-boot System
  146.  
  147. L0030:    POP    ES            ; restore registers
  148.     POP    DS
  149.     POP    DX
  150.     POP    CX
  151.     POP    BX
  152.     POP    AX
  153.     MOV    AH,0D0H         ; set printer status OK
  154.     IRET                ; and return to caller
  155.  
  156.     IF    ($-SEGADDR) MOD 16    ; check if on segment boundary
  157. ;
  158.     ORG    ($-SEGADDR)+16-(($-SEGADDR) MOD 16)
  159.                     ; assure segment boundary
  160.     ENDIF
  161. BUFFER    EQU    THIS BYTE
  162. ;
  163.     SUBTTL    INITIALIZATION SECTION
  164.     PAGE
  165. ;
  166. ; Note that this section of code
  167. ; is overlayed by the buffer
  168. ;
  169. ERRMSG1 DB    'Invalid filespec.',CR,LF,'$'
  170. INIT:
  171.     PUSH    CS            ; establish data
  172.     POP    DS            ;  segment address
  173.     XOR    AX,AX            ; AX = 0
  174.     PUSH    AX            ; set up for return to DOS
  175.     DOSCALL @CRTEF,UFCB1        ; create & open file
  176.     INC    AL
  177.     JNZ    I0010            ; if file opened ok
  178.     DOSCALL @STROUT,ERRMSG1     ; else print error msg
  179.     RET                ; return to DOS
  180. I0010:
  181.     MOV    AX,BUFLEN        ; AX <- buffer length
  182.     MOV    WORD PTR UFCB1+14,AX    ; set record length
  183.     DOSCALL @SETRND,UFCB1        ; set random record field
  184.  
  185.     MOV    AL,17H
  186.     DOSCALL @GETINT         ; Get INT 17H vector
  187.     MOV    O17_IP,BX        ;  and modify ourself
  188.     MOV    O17_CS,ES        ;  with it
  189.     MOV    AL,17H
  190.     LEA    DX,INT_17
  191.     DOSCALL @SETINT         ; Set INT 17H to us
  192.  
  193.     MOV    DX,OFFSET BUFFER    ; DX = offset of buffer
  194.     MOV    CL,4            ; CL = shift count
  195.     SHR    DX,CL            ; DX = extra segment addr for buffer
  196.     MOV    AX,CS            ; AX -> current segment
  197.     ADD    DX,AX            ; add in current CS
  198.     MOV    BUFSEG,DX        ; save segment addr of buffer
  199.  
  200.     MOV    SI,BUFLEN        ; SI = offset to buffer
  201.     LEA    DX,BUFFER[SI]        ; DX = nbr of bytes to reserve
  202.     INT    27H            ; return to DOS w/o releasing memory
  203.  
  204. CAPTURE ENDS
  205.     END    START
  206.